function ff_methods = bvqxfile_getmethods(ext)
% BVQXfile::<PRIVATE>::getmethods  - searching for methods for files
%
% THIS FUNCTION IS AN INTERNAL FUNCTION OF THE CLASS
%
% @BVQXfile
%
% AND IT SHOULD NEVER BE CALLED FROM OUTSIDE THE CLASS CODE

% Version:  v0.7f
% Build:    8110521
% Date:     Nov-05 2008, 9:00 PM CET
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% create struct
ff_methods = struct;

% get path of this m-file
spfile = mfilename('fullpath');
sppath = fileparts(spfile);

% get extension list and add special type for AllFileTypes
extlist = fieldnames(ext);
extlist{end + 1} = 'aft';

% for each extension, look for methods
for ec = 1:numel(extlist)

    % get extension and build empty sub struct
    typext  = lower(extlist{ec});
    typmst  = struct;

    % lookup methods
    typmeth = dir([sppath filesep typext '_*.m']);

    % iterate over found entries
    for mc = 1:length(typmeth)
        
        % read file
        fcont = asciiread([sppath filesep typmeth(mc).name]);
        if ~isempty(strfind(fcont, char([13, 10])))
            fcont = splittocellc(fcont, char([13, 10]), false, false);
        else
            fcont = splittocellc(fcont, char(10), false, false);
        end
        
        % get first comment line text
        try
            fcomm = regexprep(regexprep(fcont{2}, '^.*\s+\-\s+', ''), '\s*$', '');
        catch
            fcomm = '';
        end
        
        % get FORMAT line
        fline = grep(fcont, ['FOR' 'MAT']);
        if ~iscell(fline)
            fline = cellstr(fline);
        end
        
        % get TYPES line
        if ec < numel(extlist)
            tline = {upper(typext)};
        else
            tline = grep(fcont, ['TYP', 'ES:']);
            if ~isempty(tline)
                tline = regexprep(tline{1}, '^.*TYPES\:\s*', '');
                tline(tline == ' ') = [];
                tline = splittocellc(tline, ',');
            end
        end

        % put method name (without extension and typext into substruct
        mname = typmeth(mc).name(1:end-2);
        uscpos = find(mname == '_');
        if ~isempty(fline)
            fargs = regexprep(fline{1}, '^[^\(]+(\([^\)]*\))?[^\)]*$', '$1');
            fline = regexprep(fline{1}, ['^.*FOR' 'MAT\:?\s*'], '');
            typmst.(lower(mname(uscpos(1)+1:end))) = ...
                {mname, fargs, fcomm, fline, tline};
        else
            typmst.(lower(mname(uscpos(1)+1:end))) = {mname, '(...)', fcomm, ...
                [typext '.' regexprep(typmeth(mc).name, '^\w+_', '') '(...);'], tline};
        end
    end

    % put into global struct
    if numel(fieldnames(typmst)) > 0
        ff_methods.(typext) = typmst;
    end
end
